package com.shyb.lingxian.mine.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.shyb.lingxian.R;
import com.shyb.lingxian.base.BaseActivity;
import com.shyb.lingxian.base.BasePresenter;
import com.shyb.lingxian.netWork.Const;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by gs on 2018/3/26.
 */

public class XieYiWebVActivity extends BaseActivity {
    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initialize() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_xieyi);

        initHeadTitle("领先服务协议");

        StringBuffer sb = new StringBuffer();
        String newUrl = sb.append(Const.URL).append("/html/protocol.html").toString();


        final WebView webView = (WebView) findViewById(R.id.webView_aboutUs);

        WebSettings webSettings = webView.getSettings();
        webView.clearHistory();
        webView.clearFormData();
        webView.clearCache(true);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeSessionCookie();
        cookieManager.removeAllCookie();



        webSettings.setJavaScriptEnabled(true); //如果访问的页面中要与Javascript交互，则webview必须设置支持Javascript
        webSettings.setUseWideViewPort(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setLoadWithOverviewMode(true); //自适应屏幕
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
        webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl(newUrl);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                webView.loadUrl(url);
                return true;
            }
        });


        findViewById(R.id.iv_head_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }
}
